
_rm:     file format elf32-i386


Disassembly of section .text:

00000000 <main>:
#include "stat.h"
#include "user.h"

int
main(int argc, char *argv[])
{
   0:	55                   	push   %ebp
   1:	89 e5                	mov    %esp,%ebp
   3:	83 e4 f0             	and    $0xfffffff0,%esp
   6:	83 ec 20             	sub    $0x20,%esp
  int i;

  if(argc < 2){
   9:	83 7d 08 01          	cmpl   $0x1,0x8(%ebp)
   d:	7f 19                	jg     28 <main+0x28>
    printf(2, "Usage: rm files...\n");
   f:	c7 44 24 04 e6 0e 00 	movl   $0xee6,0x4(%esp)
  16:	00 
  17:	c7 04 24 02 00 00 00 	movl   $0x2,(%esp)
  1e:	e8 72 04 00 00       	call   495 <printf>
    exit();
  23:	e8 d0 02 00 00       	call   2f8 <exit>
  }

  for(i = 1; i < argc; i++){
  28:	c7 44 24 1c 01 00 00 	movl   $0x1,0x1c(%esp)
  2f:	00 
  30:	eb 4f                	jmp    81 <main+0x81>
    if(unlink(argv[i]) < 0){
  32:	8b 44 24 1c          	mov    0x1c(%esp),%eax
  36:	8d 14 85 00 00 00 00 	lea    0x0(,%eax,4),%edx
  3d:	8b 45 0c             	mov    0xc(%ebp),%eax
  40:	01 d0                	add    %edx,%eax
  42:	8b 00                	mov    (%eax),%eax
  44:	89 04 24             	mov    %eax,(%esp)
  47:	e8 fc 02 00 00       	call   348 <unlink>
  4c:	85 c0                	test   %eax,%eax
  4e:	79 2c                	jns    7c <main+0x7c>
      printf(2, "rm: %s failed to delete\n", argv[i]);
  50:	8b 44 24 1c          	mov    0x1c(%esp),%eax
  54:	8d 14 85 00 00 00 00 	lea    0x0(,%eax,4),%edx
  5b:	8b 45 0c             	mov    0xc(%ebp),%eax
  5e:	01 d0                	add    %edx,%eax
  60:	8b 00                	mov    (%eax),%eax
  62:	89 44 24 08          	mov    %eax,0x8(%esp)
  66:	c7 44 24 04 fa 0e 00 	movl   $0xefa,0x4(%esp)
  6d:	00 
  6e:	c7 04 24 02 00 00 00 	movl   $0x2,(%esp)
  75:	e8 1b 04 00 00       	call   495 <printf>
      break;
  7a:	eb 0e                	jmp    8a <main+0x8a>
  if(argc < 2){
    printf(2, "Usage: rm files...\n");
    exit();
  }

  for(i = 1; i < argc; i++){
  7c:	83 44 24 1c 01       	addl   $0x1,0x1c(%esp)
  81:	8b 44 24 1c          	mov    0x1c(%esp),%eax
  85:	3b 45 08             	cmp    0x8(%ebp),%eax
  88:	7c a8                	jl     32 <main+0x32>
      printf(2, "rm: %s failed to delete\n", argv[i]);
      break;
    }
  }

  exit();
  8a:	e8 69 02 00 00       	call   2f8 <exit>
  8f:	90                   	nop

00000090 <stosb>:
               "cc");
}

static inline void
stosb(void *addr, int data, int cnt)
{
  90:	55                   	push   %ebp
  91:	89 e5                	mov    %esp,%ebp
  93:	57                   	push   %edi
  94:	53                   	push   %ebx
  asm volatile("cld; rep stosb" :
  95:	8b 4d 08             	mov    0x8(%ebp),%ecx
  98:	8b 55 10             	mov    0x10(%ebp),%edx
  9b:	8b 45 0c             	mov    0xc(%ebp),%eax
  9e:	89 cb                	mov    %ecx,%ebx
  a0:	89 df                	mov    %ebx,%edi
  a2:	89 d1                	mov    %edx,%ecx
  a4:	fc                   	cld    
  a5:	f3 aa                	rep stos %al,%es:(%edi)
  a7:	89 ca                	mov    %ecx,%edx
  a9:	89 fb                	mov    %edi,%ebx
  ab:	89 5d 08             	mov    %ebx,0x8(%ebp)
  ae:	89 55 10             	mov    %edx,0x10(%ebp)
               "=D" (addr), "=c" (cnt) :
               "0" (addr), "1" (cnt), "a" (data) :
               "memory", "cc");
}
  b1:	5b                   	pop    %ebx
  b2:	5f                   	pop    %edi
  b3:	5d                   	pop    %ebp
  b4:	c3                   	ret    

000000b5 <strcpy>:
#include "user.h"
#include "x86.h"

char*
strcpy(char *s, char *t)
{
  b5:	55                   	push   %ebp
  b6:	89 e5                	mov    %esp,%ebp
  b8:	83 ec 10             	sub    $0x10,%esp
  char *os;

  os = s;
  bb:	8b 45 08             	mov    0x8(%ebp),%eax
  be:	89 45 fc             	mov    %eax,-0x4(%ebp)
  while((*s++ = *t++) != 0)
  c1:	90                   	nop
  c2:	8b 45 0c             	mov    0xc(%ebp),%eax
  c5:	0f b6 10             	movzbl (%eax),%edx
  c8:	8b 45 08             	mov    0x8(%ebp),%eax
  cb:	88 10                	mov    %dl,(%eax)
  cd:	8b 45 08             	mov    0x8(%ebp),%eax
  d0:	0f b6 00             	movzbl (%eax),%eax
  d3:	84 c0                	test   %al,%al
  d5:	0f 95 c0             	setne  %al
  d8:	83 45 08 01          	addl   $0x1,0x8(%ebp)
  dc:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
  e0:	84 c0                	test   %al,%al
  e2:	75 de                	jne    c2 <strcpy+0xd>
    ;
  return os;
  e4:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
  e7:	c9                   	leave  
  e8:	c3                   	ret    

000000e9 <strcmp>:

int
strcmp(const char *p, const char *q)
{
  e9:	55                   	push   %ebp
  ea:	89 e5                	mov    %esp,%ebp
  while(*p && *p == *q)
  ec:	eb 08                	jmp    f6 <strcmp+0xd>
    p++, q++;
  ee:	83 45 08 01          	addl   $0x1,0x8(%ebp)
  f2:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
}

int
strcmp(const char *p, const char *q)
{
  while(*p && *p == *q)
  f6:	8b 45 08             	mov    0x8(%ebp),%eax
  f9:	0f b6 00             	movzbl (%eax),%eax
  fc:	84 c0                	test   %al,%al
  fe:	74 10                	je     110 <strcmp+0x27>
 100:	8b 45 08             	mov    0x8(%ebp),%eax
 103:	0f b6 10             	movzbl (%eax),%edx
 106:	8b 45 0c             	mov    0xc(%ebp),%eax
 109:	0f b6 00             	movzbl (%eax),%eax
 10c:	38 c2                	cmp    %al,%dl
 10e:	74 de                	je     ee <strcmp+0x5>
    p++, q++;
  return (uchar)*p - (uchar)*q;
 110:	8b 45 08             	mov    0x8(%ebp),%eax
 113:	0f b6 00             	movzbl (%eax),%eax
 116:	0f b6 d0             	movzbl %al,%edx
 119:	8b 45 0c             	mov    0xc(%ebp),%eax
 11c:	0f b6 00             	movzbl (%eax),%eax
 11f:	0f b6 c0             	movzbl %al,%eax
 122:	89 d1                	mov    %edx,%ecx
 124:	29 c1                	sub    %eax,%ecx
 126:	89 c8                	mov    %ecx,%eax
}
 128:	5d                   	pop    %ebp
 129:	c3                   	ret    

0000012a <strlen>:

uint
strlen(char *s)
{
 12a:	55                   	push   %ebp
 12b:	89 e5                	mov    %esp,%ebp
 12d:	83 ec 10             	sub    $0x10,%esp
  int n;

  for(n = 0; s[n]; n++)
 130:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
 137:	eb 04                	jmp    13d <strlen+0x13>
 139:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 13d:	8b 55 fc             	mov    -0x4(%ebp),%edx
 140:	8b 45 08             	mov    0x8(%ebp),%eax
 143:	01 d0                	add    %edx,%eax
 145:	0f b6 00             	movzbl (%eax),%eax
 148:	84 c0                	test   %al,%al
 14a:	75 ed                	jne    139 <strlen+0xf>
    ;
  return n;
 14c:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
 14f:	c9                   	leave  
 150:	c3                   	ret    

00000151 <memset>:

void*
memset(void *dst, int c, uint n)
{
 151:	55                   	push   %ebp
 152:	89 e5                	mov    %esp,%ebp
 154:	83 ec 0c             	sub    $0xc,%esp
  stosb(dst, c, n);
 157:	8b 45 10             	mov    0x10(%ebp),%eax
 15a:	89 44 24 08          	mov    %eax,0x8(%esp)
 15e:	8b 45 0c             	mov    0xc(%ebp),%eax
 161:	89 44 24 04          	mov    %eax,0x4(%esp)
 165:	8b 45 08             	mov    0x8(%ebp),%eax
 168:	89 04 24             	mov    %eax,(%esp)
 16b:	e8 20 ff ff ff       	call   90 <stosb>
  return dst;
 170:	8b 45 08             	mov    0x8(%ebp),%eax
}
 173:	c9                   	leave  
 174:	c3                   	ret    

00000175 <strchr>:

char*
strchr(const char *s, char c)
{
 175:	55                   	push   %ebp
 176:	89 e5                	mov    %esp,%ebp
 178:	83 ec 04             	sub    $0x4,%esp
 17b:	8b 45 0c             	mov    0xc(%ebp),%eax
 17e:	88 45 fc             	mov    %al,-0x4(%ebp)
  for(; *s; s++)
 181:	eb 14                	jmp    197 <strchr+0x22>
    if(*s == c)
 183:	8b 45 08             	mov    0x8(%ebp),%eax
 186:	0f b6 00             	movzbl (%eax),%eax
 189:	3a 45 fc             	cmp    -0x4(%ebp),%al
 18c:	75 05                	jne    193 <strchr+0x1e>
      return (char*)s;
 18e:	8b 45 08             	mov    0x8(%ebp),%eax
 191:	eb 13                	jmp    1a6 <strchr+0x31>
}

char*
strchr(const char *s, char c)
{
  for(; *s; s++)
 193:	83 45 08 01          	addl   $0x1,0x8(%ebp)
 197:	8b 45 08             	mov    0x8(%ebp),%eax
 19a:	0f b6 00             	movzbl (%eax),%eax
 19d:	84 c0                	test   %al,%al
 19f:	75 e2                	jne    183 <strchr+0xe>
    if(*s == c)
      return (char*)s;
  return 0;
 1a1:	b8 00 00 00 00       	mov    $0x0,%eax
}
 1a6:	c9                   	leave  
 1a7:	c3                   	ret    

000001a8 <gets>:

char*
gets(char *buf, int max)
{
 1a8:	55                   	push   %ebp
 1a9:	89 e5                	mov    %esp,%ebp
 1ab:	83 ec 28             	sub    $0x28,%esp
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
 1ae:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 1b5:	eb 46                	jmp    1fd <gets+0x55>
    cc = read(0, &c, 1);
 1b7:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
 1be:	00 
 1bf:	8d 45 ef             	lea    -0x11(%ebp),%eax
 1c2:	89 44 24 04          	mov    %eax,0x4(%esp)
 1c6:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 1cd:	e8 3e 01 00 00       	call   310 <read>
 1d2:	89 45 f0             	mov    %eax,-0x10(%ebp)
    if(cc < 1)
 1d5:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 1d9:	7e 2f                	jle    20a <gets+0x62>
      break;
    buf[i++] = c;
 1db:	8b 55 f4             	mov    -0xc(%ebp),%edx
 1de:	8b 45 08             	mov    0x8(%ebp),%eax
 1e1:	01 c2                	add    %eax,%edx
 1e3:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 1e7:	88 02                	mov    %al,(%edx)
 1e9:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
    if(c == '\n' || c == '\r')
 1ed:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 1f1:	3c 0a                	cmp    $0xa,%al
 1f3:	74 16                	je     20b <gets+0x63>
 1f5:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 1f9:	3c 0d                	cmp    $0xd,%al
 1fb:	74 0e                	je     20b <gets+0x63>
gets(char *buf, int max)
{
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
 1fd:	8b 45 f4             	mov    -0xc(%ebp),%eax
 200:	83 c0 01             	add    $0x1,%eax
 203:	3b 45 0c             	cmp    0xc(%ebp),%eax
 206:	7c af                	jl     1b7 <gets+0xf>
 208:	eb 01                	jmp    20b <gets+0x63>
    cc = read(0, &c, 1);
    if(cc < 1)
      break;
 20a:	90                   	nop
    buf[i++] = c;
    if(c == '\n' || c == '\r')
      break;
  }
  buf[i] = '\0';
 20b:	8b 55 f4             	mov    -0xc(%ebp),%edx
 20e:	8b 45 08             	mov    0x8(%ebp),%eax
 211:	01 d0                	add    %edx,%eax
 213:	c6 00 00             	movb   $0x0,(%eax)
  return buf;
 216:	8b 45 08             	mov    0x8(%ebp),%eax
}
 219:	c9                   	leave  
 21a:	c3                   	ret    

0000021b <stat>:

int
stat(char *n, struct stat *st)
{
 21b:	55                   	push   %ebp
 21c:	89 e5                	mov    %esp,%ebp
 21e:	83 ec 28             	sub    $0x28,%esp
  int fd;
  int r;

  fd = open(n, O_RDONLY);
 221:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
 228:	00 
 229:	8b 45 08             	mov    0x8(%ebp),%eax
 22c:	89 04 24             	mov    %eax,(%esp)
 22f:	e8 04 01 00 00       	call   338 <open>
 234:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(fd < 0)
 237:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 23b:	79 07                	jns    244 <stat+0x29>
    return -1;
 23d:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
 242:	eb 23                	jmp    267 <stat+0x4c>
  r = fstat(fd, st);
 244:	8b 45 0c             	mov    0xc(%ebp),%eax
 247:	89 44 24 04          	mov    %eax,0x4(%esp)
 24b:	8b 45 f4             	mov    -0xc(%ebp),%eax
 24e:	89 04 24             	mov    %eax,(%esp)
 251:	e8 fa 00 00 00       	call   350 <fstat>
 256:	89 45 f0             	mov    %eax,-0x10(%ebp)
  close(fd);
 259:	8b 45 f4             	mov    -0xc(%ebp),%eax
 25c:	89 04 24             	mov    %eax,(%esp)
 25f:	e8 bc 00 00 00       	call   320 <close>
  return r;
 264:	8b 45 f0             	mov    -0x10(%ebp),%eax
}
 267:	c9                   	leave  
 268:	c3                   	ret    

00000269 <atoi>:

int
atoi(const char *s)
{
 269:	55                   	push   %ebp
 26a:	89 e5                	mov    %esp,%ebp
 26c:	83 ec 10             	sub    $0x10,%esp
  int n;

  n = 0;
 26f:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
  while('0' <= *s && *s <= '9')
 276:	eb 23                	jmp    29b <atoi+0x32>
    n = n*10 + *s++ - '0';
 278:	8b 55 fc             	mov    -0x4(%ebp),%edx
 27b:	89 d0                	mov    %edx,%eax
 27d:	c1 e0 02             	shl    $0x2,%eax
 280:	01 d0                	add    %edx,%eax
 282:	01 c0                	add    %eax,%eax
 284:	89 c2                	mov    %eax,%edx
 286:	8b 45 08             	mov    0x8(%ebp),%eax
 289:	0f b6 00             	movzbl (%eax),%eax
 28c:	0f be c0             	movsbl %al,%eax
 28f:	01 d0                	add    %edx,%eax
 291:	83 e8 30             	sub    $0x30,%eax
 294:	89 45 fc             	mov    %eax,-0x4(%ebp)
 297:	83 45 08 01          	addl   $0x1,0x8(%ebp)
atoi(const char *s)
{
  int n;

  n = 0;
  while('0' <= *s && *s <= '9')
 29b:	8b 45 08             	mov    0x8(%ebp),%eax
 29e:	0f b6 00             	movzbl (%eax),%eax
 2a1:	3c 2f                	cmp    $0x2f,%al
 2a3:	7e 0a                	jle    2af <atoi+0x46>
 2a5:	8b 45 08             	mov    0x8(%ebp),%eax
 2a8:	0f b6 00             	movzbl (%eax),%eax
 2ab:	3c 39                	cmp    $0x39,%al
 2ad:	7e c9                	jle    278 <atoi+0xf>
    n = n*10 + *s++ - '0';
  return n;
 2af:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
 2b2:	c9                   	leave  
 2b3:	c3                   	ret    

000002b4 <memmove>:

void*
memmove(void *vdst, void *vsrc, int n)
{
 2b4:	55                   	push   %ebp
 2b5:	89 e5                	mov    %esp,%ebp
 2b7:	83 ec 10             	sub    $0x10,%esp
  char *dst, *src;
  
  dst = vdst;
 2ba:	8b 45 08             	mov    0x8(%ebp),%eax
 2bd:	89 45 fc             	mov    %eax,-0x4(%ebp)
  src = vsrc;
 2c0:	8b 45 0c             	mov    0xc(%ebp),%eax
 2c3:	89 45 f8             	mov    %eax,-0x8(%ebp)
  while(n-- > 0)
 2c6:	eb 13                	jmp    2db <memmove+0x27>
    *dst++ = *src++;
 2c8:	8b 45 f8             	mov    -0x8(%ebp),%eax
 2cb:	0f b6 10             	movzbl (%eax),%edx
 2ce:	8b 45 fc             	mov    -0x4(%ebp),%eax
 2d1:	88 10                	mov    %dl,(%eax)
 2d3:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 2d7:	83 45 f8 01          	addl   $0x1,-0x8(%ebp)
{
  char *dst, *src;
  
  dst = vdst;
  src = vsrc;
  while(n-- > 0)
 2db:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
 2df:	0f 9f c0             	setg   %al
 2e2:	83 6d 10 01          	subl   $0x1,0x10(%ebp)
 2e6:	84 c0                	test   %al,%al
 2e8:	75 de                	jne    2c8 <memmove+0x14>
    *dst++ = *src++;
  return vdst;
 2ea:	8b 45 08             	mov    0x8(%ebp),%eax
}
 2ed:	c9                   	leave  
 2ee:	c3                   	ret    
 2ef:	90                   	nop

000002f0 <fork>:
  name: \
    movl $SYS_ ## name, %eax; \
    int $T_SYSCALL; \
    ret

SYSCALL(fork)
 2f0:	b8 01 00 00 00       	mov    $0x1,%eax
 2f5:	cd 40                	int    $0x40
 2f7:	c3                   	ret    

000002f8 <exit>:
SYSCALL(exit)
 2f8:	b8 02 00 00 00       	mov    $0x2,%eax
 2fd:	cd 40                	int    $0x40
 2ff:	c3                   	ret    

00000300 <wait>:
SYSCALL(wait)
 300:	b8 03 00 00 00       	mov    $0x3,%eax
 305:	cd 40                	int    $0x40
 307:	c3                   	ret    

00000308 <pipe>:
SYSCALL(pipe)
 308:	b8 04 00 00 00       	mov    $0x4,%eax
 30d:	cd 40                	int    $0x40
 30f:	c3                   	ret    

00000310 <read>:
SYSCALL(read)
 310:	b8 05 00 00 00       	mov    $0x5,%eax
 315:	cd 40                	int    $0x40
 317:	c3                   	ret    

00000318 <write>:
SYSCALL(write)
 318:	b8 10 00 00 00       	mov    $0x10,%eax
 31d:	cd 40                	int    $0x40
 31f:	c3                   	ret    

00000320 <close>:
SYSCALL(close)
 320:	b8 15 00 00 00       	mov    $0x15,%eax
 325:	cd 40                	int    $0x40
 327:	c3                   	ret    

00000328 <kill>:
SYSCALL(kill)
 328:	b8 06 00 00 00       	mov    $0x6,%eax
 32d:	cd 40                	int    $0x40
 32f:	c3                   	ret    

00000330 <exec>:
SYSCALL(exec)
 330:	b8 07 00 00 00       	mov    $0x7,%eax
 335:	cd 40                	int    $0x40
 337:	c3                   	ret    

00000338 <open>:
SYSCALL(open)
 338:	b8 0f 00 00 00       	mov    $0xf,%eax
 33d:	cd 40                	int    $0x40
 33f:	c3                   	ret    

00000340 <mknod>:
SYSCALL(mknod)
 340:	b8 11 00 00 00       	mov    $0x11,%eax
 345:	cd 40                	int    $0x40
 347:	c3                   	ret    

00000348 <unlink>:
SYSCALL(unlink)
 348:	b8 12 00 00 00       	mov    $0x12,%eax
 34d:	cd 40                	int    $0x40
 34f:	c3                   	ret    

00000350 <fstat>:
SYSCALL(fstat)
 350:	b8 08 00 00 00       	mov    $0x8,%eax
 355:	cd 40                	int    $0x40
 357:	c3                   	ret    

00000358 <link>:
SYSCALL(link)
 358:	b8 13 00 00 00       	mov    $0x13,%eax
 35d:	cd 40                	int    $0x40
 35f:	c3                   	ret    

00000360 <mkdir>:
SYSCALL(mkdir)
 360:	b8 14 00 00 00       	mov    $0x14,%eax
 365:	cd 40                	int    $0x40
 367:	c3                   	ret    

00000368 <chdir>:
SYSCALL(chdir)
 368:	b8 09 00 00 00       	mov    $0x9,%eax
 36d:	cd 40                	int    $0x40
 36f:	c3                   	ret    

00000370 <dup>:
SYSCALL(dup)
 370:	b8 0a 00 00 00       	mov    $0xa,%eax
 375:	cd 40                	int    $0x40
 377:	c3                   	ret    

00000378 <getpid>:
SYSCALL(getpid)
 378:	b8 0b 00 00 00       	mov    $0xb,%eax
 37d:	cd 40                	int    $0x40
 37f:	c3                   	ret    

00000380 <sbrk>:
SYSCALL(sbrk)
 380:	b8 0c 00 00 00       	mov    $0xc,%eax
 385:	cd 40                	int    $0x40
 387:	c3                   	ret    

00000388 <sleep>:
SYSCALL(sleep)
 388:	b8 0d 00 00 00       	mov    $0xd,%eax
 38d:	cd 40                	int    $0x40
 38f:	c3                   	ret    

00000390 <uptime>:
SYSCALL(uptime)
 390:	b8 0e 00 00 00       	mov    $0xe,%eax
 395:	cd 40                	int    $0x40
 397:	c3                   	ret    

00000398 <signal>:

//our addition
SYSCALL(signal)
 398:	b8 1f 00 00 00       	mov    $0x1f,%eax
 39d:	cd 40                	int    $0x40
 39f:	c3                   	ret    

000003a0 <sigsend>:
SYSCALL(sigsend)
 3a0:	b8 20 00 00 00       	mov    $0x20,%eax
 3a5:	cd 40                	int    $0x40
 3a7:	c3                   	ret    

000003a8 <alarm>:
SYSCALL(alarm)
 3a8:	b8 21 00 00 00       	mov    $0x21,%eax
 3ad:	cd 40                	int    $0x40
 3af:	c3                   	ret    

000003b0 <getTicks>:
SYSCALL(getTicks)
 3b0:	b8 22 00 00 00       	mov    $0x22,%eax
 3b5:	cd 40                	int    $0x40
 3b7:	c3                   	ret    

000003b8 <putc>:
#include "stat.h"
#include "user.h"

static void
putc(int fd, char c)
{
 3b8:	55                   	push   %ebp
 3b9:	89 e5                	mov    %esp,%ebp
 3bb:	83 ec 28             	sub    $0x28,%esp
 3be:	8b 45 0c             	mov    0xc(%ebp),%eax
 3c1:	88 45 f4             	mov    %al,-0xc(%ebp)
  write(fd, &c, 1);
 3c4:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
 3cb:	00 
 3cc:	8d 45 f4             	lea    -0xc(%ebp),%eax
 3cf:	89 44 24 04          	mov    %eax,0x4(%esp)
 3d3:	8b 45 08             	mov    0x8(%ebp),%eax
 3d6:	89 04 24             	mov    %eax,(%esp)
 3d9:	e8 3a ff ff ff       	call   318 <write>
}
 3de:	c9                   	leave  
 3df:	c3                   	ret    

000003e0 <printint>:

static void
printint(int fd, int xx, int base, int sgn)
{
 3e0:	55                   	push   %ebp
 3e1:	89 e5                	mov    %esp,%ebp
 3e3:	83 ec 48             	sub    $0x48,%esp
  static char digits[] = "0123456789ABCDEF";
  char buf[16];
  int i, neg;
  uint x;

  neg = 0;
 3e6:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
  if(sgn && xx < 0){
 3ed:	83 7d 14 00          	cmpl   $0x0,0x14(%ebp)
 3f1:	74 17                	je     40a <printint+0x2a>
 3f3:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
 3f7:	79 11                	jns    40a <printint+0x2a>
    neg = 1;
 3f9:	c7 45 f0 01 00 00 00 	movl   $0x1,-0x10(%ebp)
    x = -xx;
 400:	8b 45 0c             	mov    0xc(%ebp),%eax
 403:	f7 d8                	neg    %eax
 405:	89 45 ec             	mov    %eax,-0x14(%ebp)
 408:	eb 06                	jmp    410 <printint+0x30>
  } else {
    x = xx;
 40a:	8b 45 0c             	mov    0xc(%ebp),%eax
 40d:	89 45 ec             	mov    %eax,-0x14(%ebp)
  }

  i = 0;
 410:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
  do{
    buf[i++] = digits[x % base];
 417:	8b 4d 10             	mov    0x10(%ebp),%ecx
 41a:	8b 45 ec             	mov    -0x14(%ebp),%eax
 41d:	ba 00 00 00 00       	mov    $0x0,%edx
 422:	f7 f1                	div    %ecx
 424:	89 d0                	mov    %edx,%eax
 426:	0f b6 80 70 13 00 00 	movzbl 0x1370(%eax),%eax
 42d:	8d 4d dc             	lea    -0x24(%ebp),%ecx
 430:	8b 55 f4             	mov    -0xc(%ebp),%edx
 433:	01 ca                	add    %ecx,%edx
 435:	88 02                	mov    %al,(%edx)
 437:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
  }while((x /= base) != 0);
 43b:	8b 55 10             	mov    0x10(%ebp),%edx
 43e:	89 55 d4             	mov    %edx,-0x2c(%ebp)
 441:	8b 45 ec             	mov    -0x14(%ebp),%eax
 444:	ba 00 00 00 00       	mov    $0x0,%edx
 449:	f7 75 d4             	divl   -0x2c(%ebp)
 44c:	89 45 ec             	mov    %eax,-0x14(%ebp)
 44f:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
 453:	75 c2                	jne    417 <printint+0x37>
  if(neg)
 455:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 459:	74 2e                	je     489 <printint+0xa9>
    buf[i++] = '-';
 45b:	8d 55 dc             	lea    -0x24(%ebp),%edx
 45e:	8b 45 f4             	mov    -0xc(%ebp),%eax
 461:	01 d0                	add    %edx,%eax
 463:	c6 00 2d             	movb   $0x2d,(%eax)
 466:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)

  while(--i >= 0)
 46a:	eb 1d                	jmp    489 <printint+0xa9>
    putc(fd, buf[i]);
 46c:	8d 55 dc             	lea    -0x24(%ebp),%edx
 46f:	8b 45 f4             	mov    -0xc(%ebp),%eax
 472:	01 d0                	add    %edx,%eax
 474:	0f b6 00             	movzbl (%eax),%eax
 477:	0f be c0             	movsbl %al,%eax
 47a:	89 44 24 04          	mov    %eax,0x4(%esp)
 47e:	8b 45 08             	mov    0x8(%ebp),%eax
 481:	89 04 24             	mov    %eax,(%esp)
 484:	e8 2f ff ff ff       	call   3b8 <putc>
    buf[i++] = digits[x % base];
  }while((x /= base) != 0);
  if(neg)
    buf[i++] = '-';

  while(--i >= 0)
 489:	83 6d f4 01          	subl   $0x1,-0xc(%ebp)
 48d:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 491:	79 d9                	jns    46c <printint+0x8c>
    putc(fd, buf[i]);
}
 493:	c9                   	leave  
 494:	c3                   	ret    

00000495 <printf>:

// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
 495:	55                   	push   %ebp
 496:	89 e5                	mov    %esp,%ebp
 498:	83 ec 38             	sub    $0x38,%esp
  char *s;
  int c, i, state;
  uint *ap;

  state = 0;
 49b:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  ap = (uint*)(void*)&fmt + 1;
 4a2:	8d 45 0c             	lea    0xc(%ebp),%eax
 4a5:	83 c0 04             	add    $0x4,%eax
 4a8:	89 45 e8             	mov    %eax,-0x18(%ebp)
  for(i = 0; fmt[i]; i++){
 4ab:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
 4b2:	e9 7d 01 00 00       	jmp    634 <printf+0x19f>
    c = fmt[i] & 0xff;
 4b7:	8b 55 0c             	mov    0xc(%ebp),%edx
 4ba:	8b 45 f0             	mov    -0x10(%ebp),%eax
 4bd:	01 d0                	add    %edx,%eax
 4bf:	0f b6 00             	movzbl (%eax),%eax
 4c2:	0f be c0             	movsbl %al,%eax
 4c5:	25 ff 00 00 00       	and    $0xff,%eax
 4ca:	89 45 e4             	mov    %eax,-0x1c(%ebp)
    if(state == 0){
 4cd:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
 4d1:	75 2c                	jne    4ff <printf+0x6a>
      if(c == '%'){
 4d3:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
 4d7:	75 0c                	jne    4e5 <printf+0x50>
        state = '%';
 4d9:	c7 45 ec 25 00 00 00 	movl   $0x25,-0x14(%ebp)
 4e0:	e9 4b 01 00 00       	jmp    630 <printf+0x19b>
      } else {
        putc(fd, c);
 4e5:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 4e8:	0f be c0             	movsbl %al,%eax
 4eb:	89 44 24 04          	mov    %eax,0x4(%esp)
 4ef:	8b 45 08             	mov    0x8(%ebp),%eax
 4f2:	89 04 24             	mov    %eax,(%esp)
 4f5:	e8 be fe ff ff       	call   3b8 <putc>
 4fa:	e9 31 01 00 00       	jmp    630 <printf+0x19b>
      }
    } else if(state == '%'){
 4ff:	83 7d ec 25          	cmpl   $0x25,-0x14(%ebp)
 503:	0f 85 27 01 00 00    	jne    630 <printf+0x19b>
      if(c == 'd'){
 509:	83 7d e4 64          	cmpl   $0x64,-0x1c(%ebp)
 50d:	75 2d                	jne    53c <printf+0xa7>
        printint(fd, *ap, 10, 1);
 50f:	8b 45 e8             	mov    -0x18(%ebp),%eax
 512:	8b 00                	mov    (%eax),%eax
 514:	c7 44 24 0c 01 00 00 	movl   $0x1,0xc(%esp)
 51b:	00 
 51c:	c7 44 24 08 0a 00 00 	movl   $0xa,0x8(%esp)
 523:	00 
 524:	89 44 24 04          	mov    %eax,0x4(%esp)
 528:	8b 45 08             	mov    0x8(%ebp),%eax
 52b:	89 04 24             	mov    %eax,(%esp)
 52e:	e8 ad fe ff ff       	call   3e0 <printint>
        ap++;
 533:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 537:	e9 ed 00 00 00       	jmp    629 <printf+0x194>
      } else if(c == 'x' || c == 'p'){
 53c:	83 7d e4 78          	cmpl   $0x78,-0x1c(%ebp)
 540:	74 06                	je     548 <printf+0xb3>
 542:	83 7d e4 70          	cmpl   $0x70,-0x1c(%ebp)
 546:	75 2d                	jne    575 <printf+0xe0>
        printint(fd, *ap, 16, 0);
 548:	8b 45 e8             	mov    -0x18(%ebp),%eax
 54b:	8b 00                	mov    (%eax),%eax
 54d:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
 554:	00 
 555:	c7 44 24 08 10 00 00 	movl   $0x10,0x8(%esp)
 55c:	00 
 55d:	89 44 24 04          	mov    %eax,0x4(%esp)
 561:	8b 45 08             	mov    0x8(%ebp),%eax
 564:	89 04 24             	mov    %eax,(%esp)
 567:	e8 74 fe ff ff       	call   3e0 <printint>
        ap++;
 56c:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 570:	e9 b4 00 00 00       	jmp    629 <printf+0x194>
      } else if(c == 's'){
 575:	83 7d e4 73          	cmpl   $0x73,-0x1c(%ebp)
 579:	75 46                	jne    5c1 <printf+0x12c>
        s = (char*)*ap;
 57b:	8b 45 e8             	mov    -0x18(%ebp),%eax
 57e:	8b 00                	mov    (%eax),%eax
 580:	89 45 f4             	mov    %eax,-0xc(%ebp)
        ap++;
 583:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
        if(s == 0)
 587:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 58b:	75 27                	jne    5b4 <printf+0x11f>
          s = "(null)";
 58d:	c7 45 f4 13 0f 00 00 	movl   $0xf13,-0xc(%ebp)
        while(*s != 0){
 594:	eb 1e                	jmp    5b4 <printf+0x11f>
          putc(fd, *s);
 596:	8b 45 f4             	mov    -0xc(%ebp),%eax
 599:	0f b6 00             	movzbl (%eax),%eax
 59c:	0f be c0             	movsbl %al,%eax
 59f:	89 44 24 04          	mov    %eax,0x4(%esp)
 5a3:	8b 45 08             	mov    0x8(%ebp),%eax
 5a6:	89 04 24             	mov    %eax,(%esp)
 5a9:	e8 0a fe ff ff       	call   3b8 <putc>
          s++;
 5ae:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 5b2:	eb 01                	jmp    5b5 <printf+0x120>
      } else if(c == 's'){
        s = (char*)*ap;
        ap++;
        if(s == 0)
          s = "(null)";
        while(*s != 0){
 5b4:	90                   	nop
 5b5:	8b 45 f4             	mov    -0xc(%ebp),%eax
 5b8:	0f b6 00             	movzbl (%eax),%eax
 5bb:	84 c0                	test   %al,%al
 5bd:	75 d7                	jne    596 <printf+0x101>
 5bf:	eb 68                	jmp    629 <printf+0x194>
          putc(fd, *s);
          s++;
        }
      } else if(c == 'c'){
 5c1:	83 7d e4 63          	cmpl   $0x63,-0x1c(%ebp)
 5c5:	75 1d                	jne    5e4 <printf+0x14f>
        putc(fd, *ap);
 5c7:	8b 45 e8             	mov    -0x18(%ebp),%eax
 5ca:	8b 00                	mov    (%eax),%eax
 5cc:	0f be c0             	movsbl %al,%eax
 5cf:	89 44 24 04          	mov    %eax,0x4(%esp)
 5d3:	8b 45 08             	mov    0x8(%ebp),%eax
 5d6:	89 04 24             	mov    %eax,(%esp)
 5d9:	e8 da fd ff ff       	call   3b8 <putc>
        ap++;
 5de:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 5e2:	eb 45                	jmp    629 <printf+0x194>
      } else if(c == '%'){
 5e4:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
 5e8:	75 17                	jne    601 <printf+0x16c>
        putc(fd, c);
 5ea:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 5ed:	0f be c0             	movsbl %al,%eax
 5f0:	89 44 24 04          	mov    %eax,0x4(%esp)
 5f4:	8b 45 08             	mov    0x8(%ebp),%eax
 5f7:	89 04 24             	mov    %eax,(%esp)
 5fa:	e8 b9 fd ff ff       	call   3b8 <putc>
 5ff:	eb 28                	jmp    629 <printf+0x194>
      } else {
        // Unknown % sequence.  Print it to draw attention.
        putc(fd, '%');
 601:	c7 44 24 04 25 00 00 	movl   $0x25,0x4(%esp)
 608:	00 
 609:	8b 45 08             	mov    0x8(%ebp),%eax
 60c:	89 04 24             	mov    %eax,(%esp)
 60f:	e8 a4 fd ff ff       	call   3b8 <putc>
        putc(fd, c);
 614:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 617:	0f be c0             	movsbl %al,%eax
 61a:	89 44 24 04          	mov    %eax,0x4(%esp)
 61e:	8b 45 08             	mov    0x8(%ebp),%eax
 621:	89 04 24             	mov    %eax,(%esp)
 624:	e8 8f fd ff ff       	call   3b8 <putc>
      }
      state = 0;
 629:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  int c, i, state;
  uint *ap;

  state = 0;
  ap = (uint*)(void*)&fmt + 1;
  for(i = 0; fmt[i]; i++){
 630:	83 45 f0 01          	addl   $0x1,-0x10(%ebp)
 634:	8b 55 0c             	mov    0xc(%ebp),%edx
 637:	8b 45 f0             	mov    -0x10(%ebp),%eax
 63a:	01 d0                	add    %edx,%eax
 63c:	0f b6 00             	movzbl (%eax),%eax
 63f:	84 c0                	test   %al,%al
 641:	0f 85 70 fe ff ff    	jne    4b7 <printf+0x22>
        putc(fd, c);
      }
      state = 0;
    }
  }
}
 647:	c9                   	leave  
 648:	c3                   	ret    
 649:	66 90                	xchg   %ax,%ax
 64b:	90                   	nop

0000064c <free>:
static Header base;
static Header *freep;

void
free(void *ap)
{
 64c:	55                   	push   %ebp
 64d:	89 e5                	mov    %esp,%ebp
 64f:	83 ec 10             	sub    $0x10,%esp
  Header *bp, *p;

  bp = (Header*)ap - 1;
 652:	8b 45 08             	mov    0x8(%ebp),%eax
 655:	83 e8 08             	sub    $0x8,%eax
 658:	89 45 f8             	mov    %eax,-0x8(%ebp)
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
 65b:	a1 a8 13 00 00       	mov    0x13a8,%eax
 660:	89 45 fc             	mov    %eax,-0x4(%ebp)
 663:	eb 24                	jmp    689 <free+0x3d>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
 665:	8b 45 fc             	mov    -0x4(%ebp),%eax
 668:	8b 00                	mov    (%eax),%eax
 66a:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 66d:	77 12                	ja     681 <free+0x35>
 66f:	8b 45 f8             	mov    -0x8(%ebp),%eax
 672:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 675:	77 24                	ja     69b <free+0x4f>
 677:	8b 45 fc             	mov    -0x4(%ebp),%eax
 67a:	8b 00                	mov    (%eax),%eax
 67c:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 67f:	77 1a                	ja     69b <free+0x4f>
free(void *ap)
{
  Header *bp, *p;

  bp = (Header*)ap - 1;
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
 681:	8b 45 fc             	mov    -0x4(%ebp),%eax
 684:	8b 00                	mov    (%eax),%eax
 686:	89 45 fc             	mov    %eax,-0x4(%ebp)
 689:	8b 45 f8             	mov    -0x8(%ebp),%eax
 68c:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 68f:	76 d4                	jbe    665 <free+0x19>
 691:	8b 45 fc             	mov    -0x4(%ebp),%eax
 694:	8b 00                	mov    (%eax),%eax
 696:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 699:	76 ca                	jbe    665 <free+0x19>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
      break;
  if(bp + bp->s.size == p->s.ptr){
 69b:	8b 45 f8             	mov    -0x8(%ebp),%eax
 69e:	8b 40 04             	mov    0x4(%eax),%eax
 6a1:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
 6a8:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6ab:	01 c2                	add    %eax,%edx
 6ad:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6b0:	8b 00                	mov    (%eax),%eax
 6b2:	39 c2                	cmp    %eax,%edx
 6b4:	75 24                	jne    6da <free+0x8e>
    bp->s.size += p->s.ptr->s.size;
 6b6:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6b9:	8b 50 04             	mov    0x4(%eax),%edx
 6bc:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6bf:	8b 00                	mov    (%eax),%eax
 6c1:	8b 40 04             	mov    0x4(%eax),%eax
 6c4:	01 c2                	add    %eax,%edx
 6c6:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6c9:	89 50 04             	mov    %edx,0x4(%eax)
    bp->s.ptr = p->s.ptr->s.ptr;
 6cc:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6cf:	8b 00                	mov    (%eax),%eax
 6d1:	8b 10                	mov    (%eax),%edx
 6d3:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6d6:	89 10                	mov    %edx,(%eax)
 6d8:	eb 0a                	jmp    6e4 <free+0x98>
  } else
    bp->s.ptr = p->s.ptr;
 6da:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6dd:	8b 10                	mov    (%eax),%edx
 6df:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6e2:	89 10                	mov    %edx,(%eax)
  if(p + p->s.size == bp){
 6e4:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6e7:	8b 40 04             	mov    0x4(%eax),%eax
 6ea:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
 6f1:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6f4:	01 d0                	add    %edx,%eax
 6f6:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 6f9:	75 20                	jne    71b <free+0xcf>
    p->s.size += bp->s.size;
 6fb:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6fe:	8b 50 04             	mov    0x4(%eax),%edx
 701:	8b 45 f8             	mov    -0x8(%ebp),%eax
 704:	8b 40 04             	mov    0x4(%eax),%eax
 707:	01 c2                	add    %eax,%edx
 709:	8b 45 fc             	mov    -0x4(%ebp),%eax
 70c:	89 50 04             	mov    %edx,0x4(%eax)
    p->s.ptr = bp->s.ptr;
 70f:	8b 45 f8             	mov    -0x8(%ebp),%eax
 712:	8b 10                	mov    (%eax),%edx
 714:	8b 45 fc             	mov    -0x4(%ebp),%eax
 717:	89 10                	mov    %edx,(%eax)
 719:	eb 08                	jmp    723 <free+0xd7>
  } else
    p->s.ptr = bp;
 71b:	8b 45 fc             	mov    -0x4(%ebp),%eax
 71e:	8b 55 f8             	mov    -0x8(%ebp),%edx
 721:	89 10                	mov    %edx,(%eax)
  freep = p;
 723:	8b 45 fc             	mov    -0x4(%ebp),%eax
 726:	a3 a8 13 00 00       	mov    %eax,0x13a8
}
 72b:	c9                   	leave  
 72c:	c3                   	ret    

0000072d <morecore>:

static Header*
morecore(uint nu)
{
 72d:	55                   	push   %ebp
 72e:	89 e5                	mov    %esp,%ebp
 730:	83 ec 28             	sub    $0x28,%esp
  char *p;
  Header *hp;

  if(nu < 4096)
 733:	81 7d 08 ff 0f 00 00 	cmpl   $0xfff,0x8(%ebp)
 73a:	77 07                	ja     743 <morecore+0x16>
    nu = 4096;
 73c:	c7 45 08 00 10 00 00 	movl   $0x1000,0x8(%ebp)
  p = sbrk(nu * sizeof(Header));
 743:	8b 45 08             	mov    0x8(%ebp),%eax
 746:	c1 e0 03             	shl    $0x3,%eax
 749:	89 04 24             	mov    %eax,(%esp)
 74c:	e8 2f fc ff ff       	call   380 <sbrk>
 751:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(p == (char*)-1)
 754:	83 7d f4 ff          	cmpl   $0xffffffff,-0xc(%ebp)
 758:	75 07                	jne    761 <morecore+0x34>
    return 0;
 75a:	b8 00 00 00 00       	mov    $0x0,%eax
 75f:	eb 22                	jmp    783 <morecore+0x56>
  hp = (Header*)p;
 761:	8b 45 f4             	mov    -0xc(%ebp),%eax
 764:	89 45 f0             	mov    %eax,-0x10(%ebp)
  hp->s.size = nu;
 767:	8b 45 f0             	mov    -0x10(%ebp),%eax
 76a:	8b 55 08             	mov    0x8(%ebp),%edx
 76d:	89 50 04             	mov    %edx,0x4(%eax)
  free((void*)(hp + 1));
 770:	8b 45 f0             	mov    -0x10(%ebp),%eax
 773:	83 c0 08             	add    $0x8,%eax
 776:	89 04 24             	mov    %eax,(%esp)
 779:	e8 ce fe ff ff       	call   64c <free>
  return freep;
 77e:	a1 a8 13 00 00       	mov    0x13a8,%eax
}
 783:	c9                   	leave  
 784:	c3                   	ret    

00000785 <malloc>:

void*
malloc(uint nbytes)
{
 785:	55                   	push   %ebp
 786:	89 e5                	mov    %esp,%ebp
 788:	83 ec 28             	sub    $0x28,%esp
  Header *p, *prevp;
  uint nunits;

  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
 78b:	8b 45 08             	mov    0x8(%ebp),%eax
 78e:	83 c0 07             	add    $0x7,%eax
 791:	c1 e8 03             	shr    $0x3,%eax
 794:	83 c0 01             	add    $0x1,%eax
 797:	89 45 ec             	mov    %eax,-0x14(%ebp)
  if((prevp = freep) == 0){
 79a:	a1 a8 13 00 00       	mov    0x13a8,%eax
 79f:	89 45 f0             	mov    %eax,-0x10(%ebp)
 7a2:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 7a6:	75 23                	jne    7cb <malloc+0x46>
    base.s.ptr = freep = prevp = &base;
 7a8:	c7 45 f0 a0 13 00 00 	movl   $0x13a0,-0x10(%ebp)
 7af:	8b 45 f0             	mov    -0x10(%ebp),%eax
 7b2:	a3 a8 13 00 00       	mov    %eax,0x13a8
 7b7:	a1 a8 13 00 00       	mov    0x13a8,%eax
 7bc:	a3 a0 13 00 00       	mov    %eax,0x13a0
    base.s.size = 0;
 7c1:	c7 05 a4 13 00 00 00 	movl   $0x0,0x13a4
 7c8:	00 00 00 
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
 7cb:	8b 45 f0             	mov    -0x10(%ebp),%eax
 7ce:	8b 00                	mov    (%eax),%eax
 7d0:	89 45 f4             	mov    %eax,-0xc(%ebp)
    if(p->s.size >= nunits){
 7d3:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7d6:	8b 40 04             	mov    0x4(%eax),%eax
 7d9:	3b 45 ec             	cmp    -0x14(%ebp),%eax
 7dc:	72 4d                	jb     82b <malloc+0xa6>
      if(p->s.size == nunits)
 7de:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7e1:	8b 40 04             	mov    0x4(%eax),%eax
 7e4:	3b 45 ec             	cmp    -0x14(%ebp),%eax
 7e7:	75 0c                	jne    7f5 <malloc+0x70>
        prevp->s.ptr = p->s.ptr;
 7e9:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7ec:	8b 10                	mov    (%eax),%edx
 7ee:	8b 45 f0             	mov    -0x10(%ebp),%eax
 7f1:	89 10                	mov    %edx,(%eax)
 7f3:	eb 26                	jmp    81b <malloc+0x96>
      else {
        p->s.size -= nunits;
 7f5:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7f8:	8b 40 04             	mov    0x4(%eax),%eax
 7fb:	89 c2                	mov    %eax,%edx
 7fd:	2b 55 ec             	sub    -0x14(%ebp),%edx
 800:	8b 45 f4             	mov    -0xc(%ebp),%eax
 803:	89 50 04             	mov    %edx,0x4(%eax)
        p += p->s.size;
 806:	8b 45 f4             	mov    -0xc(%ebp),%eax
 809:	8b 40 04             	mov    0x4(%eax),%eax
 80c:	c1 e0 03             	shl    $0x3,%eax
 80f:	01 45 f4             	add    %eax,-0xc(%ebp)
        p->s.size = nunits;
 812:	8b 45 f4             	mov    -0xc(%ebp),%eax
 815:	8b 55 ec             	mov    -0x14(%ebp),%edx
 818:	89 50 04             	mov    %edx,0x4(%eax)
      }
      freep = prevp;
 81b:	8b 45 f0             	mov    -0x10(%ebp),%eax
 81e:	a3 a8 13 00 00       	mov    %eax,0x13a8
      return (void*)(p + 1);
 823:	8b 45 f4             	mov    -0xc(%ebp),%eax
 826:	83 c0 08             	add    $0x8,%eax
 829:	eb 38                	jmp    863 <malloc+0xde>
    }
    if(p == freep)
 82b:	a1 a8 13 00 00       	mov    0x13a8,%eax
 830:	39 45 f4             	cmp    %eax,-0xc(%ebp)
 833:	75 1b                	jne    850 <malloc+0xcb>
      if((p = morecore(nunits)) == 0)
 835:	8b 45 ec             	mov    -0x14(%ebp),%eax
 838:	89 04 24             	mov    %eax,(%esp)
 83b:	e8 ed fe ff ff       	call   72d <morecore>
 840:	89 45 f4             	mov    %eax,-0xc(%ebp)
 843:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 847:	75 07                	jne    850 <malloc+0xcb>
        return 0;
 849:	b8 00 00 00 00       	mov    $0x0,%eax
 84e:	eb 13                	jmp    863 <malloc+0xde>
  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
  if((prevp = freep) == 0){
    base.s.ptr = freep = prevp = &base;
    base.s.size = 0;
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
 850:	8b 45 f4             	mov    -0xc(%ebp),%eax
 853:	89 45 f0             	mov    %eax,-0x10(%ebp)
 856:	8b 45 f4             	mov    -0xc(%ebp),%eax
 859:	8b 00                	mov    (%eax),%eax
 85b:	89 45 f4             	mov    %eax,-0xc(%ebp)
      return (void*)(p + 1);
    }
    if(p == freep)
      if((p = morecore(nunits)) == 0)
        return 0;
  }
 85e:	e9 70 ff ff ff       	jmp    7d3 <malloc+0x4e>
}
 863:	c9                   	leave  
 864:	c3                   	ret    
 865:	66 90                	xchg   %ax,%ax
 867:	90                   	nop

00000868 <uthread_init>:
int c_thread = 0;

// task 2.2

void uthread_init()
{
 868:	55                   	push   %ebp
 869:	89 e5                	mov    %esp,%ebp
 86b:	83 ec 28             	sub    $0x28,%esp

	int i;
	ttable[0].tid = 0;
 86e:	c7 05 c0 13 00 00 00 	movl   $0x0,0x13c0
 875:	00 00 00 
	STORE_ESP(ttable[0].esp);
 878:	89 e0                	mov    %esp,%eax
 87a:	a3 c4 13 00 00       	mov    %eax,0x13c4
	STORE_EBP(ttable[0].ebp);
 87f:	89 e8                	mov    %ebp,%eax
 881:	a3 c8 13 00 00       	mov    %eax,0x13c8
	ttable[0].state = T_RUNNING;
 886:	c7 05 d0 13 00 00 01 	movl   $0x1,0x13d0
 88d:	00 00 00 
	ttable[0].wait_num = 0;
 890:	c7 05 d4 14 00 00 00 	movl   $0x0,0x14d4
 897:	00 00 00 
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
 89a:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
 8a1:	eb 2c                	jmp    8cf <uthread_init+0x67>
	{
		ttable[i].tid = i;
 8a3:	8b 45 f4             	mov    -0xc(%ebp),%eax
 8a6:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 8ac:	8d 90 c0 13 00 00    	lea    0x13c0(%eax),%edx
 8b2:	8b 45 f4             	mov    -0xc(%ebp),%eax
 8b5:	89 02                	mov    %eax,(%edx)
		ttable[i].state = T_FREE;
 8b7:	8b 45 f4             	mov    -0xc(%ebp),%eax
 8ba:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 8c0:	05 d0 13 00 00       	add    $0x13d0,%eax
 8c5:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	STORE_ESP(ttable[0].esp);
	STORE_EBP(ttable[0].ebp);
	ttable[0].state = T_RUNNING;
	ttable[0].wait_num = 0;
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
 8cb:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 8cf:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 8d3:	7e ce                	jle    8a3 <uthread_init+0x3b>
	{
		ttable[i].tid = i;
		ttable[i].state = T_FREE;
	}
	signal(SIGALRM, uthread_yield);
 8d5:	c7 44 24 04 5b 0b 00 	movl   $0xb5b,0x4(%esp)
 8dc:	00 
 8dd:	c7 04 24 0e 00 00 00 	movl   $0xe,(%esp)
 8e4:	e8 af fa ff ff       	call   398 <signal>
	alarm(THREAD_QUANTA);
 8e9:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
 8f0:	e8 b3 fa ff ff       	call   3a8 <alarm>
}
 8f5:	c9                   	leave  
 8f6:	c3                   	ret    

000008f7 <uthread_create>:

// task 2.3

int uthread_create(void (*start_func)(void *), void*arg)
{
 8f7:	55                   	push   %ebp
 8f8:	89 e5                	mov    %esp,%ebp
 8fa:	83 ec 28             	sub    $0x28,%esp
	int i;
	int ticks;
	asm("pusha");
 8fd:	60                   	pusha  
	ticks = getTicks();
 8fe:	e8 ad fa ff ff       	call   3b0 <getTicks>
 903:	89 45 f0             	mov    %eax,-0x10(%ebp)
	alarm(0);
 906:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 90d:	e8 96 fa ff ff       	call   3a8 <alarm>
	asm("popa");
 912:	61                   	popa   
	for (i = 0; i < MAX_THREAD; i++)
 913:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 91a:	e9 02 01 00 00       	jmp    a21 <uthread_create+0x12a>
	{
		if (ttable[i].state == T_FREE)
 91f:	8b 45 f4             	mov    -0xc(%ebp),%eax
 922:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 928:	05 d0 13 00 00       	add    $0x13d0,%eax
 92d:	8b 00                	mov    (%eax),%eax
 92f:	85 c0                	test   %eax,%eax
 931:	0f 85 e6 00 00 00    	jne    a1d <uthread_create+0x126>
		{	
			//allocate a stack for the new thread
			if ((ttable[i].stack = malloc(STACK_SIZE)) < 0)
 937:	c7 04 24 00 10 00 00 	movl   $0x1000,(%esp)
 93e:	e8 42 fe ff ff       	call   785 <malloc>
 943:	8b 55 f4             	mov    -0xc(%ebp),%edx
 946:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 94c:	81 c2 c0 13 00 00    	add    $0x13c0,%edx
 952:	89 42 0c             	mov    %eax,0xc(%edx)
			{
				alarm(ticks);
				return -1;
			}
			LOAD_ESP(ttable[i].stack + STACK_SIZE);
 955:	8b 45 f4             	mov    -0xc(%ebp),%eax
 958:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 95e:	05 c0 13 00 00       	add    $0x13c0,%eax
 963:	8b 40 0c             	mov    0xc(%eax),%eax
 966:	05 00 10 00 00       	add    $0x1000,%eax
 96b:	89 c4                	mov    %eax,%esp
			PUSH(arg);
 96d:	8b 45 0c             	mov    0xc(%ebp),%eax
 970:	89 c7                	mov    %eax,%edi
 972:	57                   	push   %edi
			PUSH(uthread_exit);
 973:	b8 e1 0b 00 00       	mov    $0xbe1,%eax
 978:	89 c7                	mov    %eax,%edi
 97a:	57                   	push   %edi
			PUSH(start_func);
 97b:	8b 45 08             	mov    0x8(%ebp),%eax
 97e:	89 c7                	mov    %eax,%edi
 980:	57                   	push   %edi
			//added for the first "pop ebp"
			PUSH(0);
 981:	b8 00 00 00 00       	mov    $0x0,%eax
 986:	89 c7                	mov    %eax,%edi
 988:	57                   	push   %edi
			STORE_ESP(ttable[i].ebp);
 989:	89 e0                	mov    %esp,%eax
 98b:	8b 55 f4             	mov    -0xc(%ebp),%edx
 98e:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 994:	81 c2 c0 13 00 00    	add    $0x13c0,%edx
 99a:	89 42 08             	mov    %eax,0x8(%edx)
			ttable[i].esp = ttable[i].ebp;
 99d:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9a0:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9a6:	05 c0 13 00 00       	add    $0x13c0,%eax
 9ab:	8b 40 08             	mov    0x8(%eax),%eax
 9ae:	8b 55 f4             	mov    -0xc(%ebp),%edx
 9b1:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 9b7:	81 c2 c0 13 00 00    	add    $0x13c0,%edx
 9bd:	89 42 04             	mov    %eax,0x4(%edx)
			//set esp to current thread's esp
			LOAD_ESP(ttable[c_thread].esp);
 9c0:	a1 ac 13 00 00       	mov    0x13ac,%eax
 9c5:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9cb:	05 c0 13 00 00       	add    $0x13c0,%eax
 9d0:	8b 40 04             	mov    0x4(%eax),%eax
 9d3:	89 c4                	mov    %eax,%esp
			ttable[i].state = T_RUNNABLE;
 9d5:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9d8:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9de:	05 d0 13 00 00       	add    $0x13d0,%eax
 9e3:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
			ttable[i].wait_num = 0;
 9e9:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9ec:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9f2:	05 d0 14 00 00       	add    $0x14d0,%eax
 9f7:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
			asm("pusha");
 9fe:	60                   	pusha  
			alarm(ticks);
 9ff:	8b 45 f0             	mov    -0x10(%ebp),%eax
 a02:	89 04 24             	mov    %eax,(%esp)
 a05:	e8 9e f9 ff ff       	call   3a8 <alarm>
			asm("popa");
 a0a:	61                   	popa   
			return ttable[i].tid;
 a0b:	8b 45 f4             	mov    -0xc(%ebp),%eax
 a0e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 a14:	05 c0 13 00 00       	add    $0x13c0,%eax
 a19:	8b 00                	mov    (%eax),%eax
 a1b:	eb 1e                	jmp    a3b <uthread_create+0x144>
	int ticks;
	asm("pusha");
	ticks = getTicks();
	alarm(0);
	asm("popa");
	for (i = 0; i < MAX_THREAD; i++)
 a1d:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 a21:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 a25:	0f 8e f4 fe ff ff    	jle    91f <uthread_create+0x28>
			asm("popa");
			return ttable[i].tid;
			
		}
	}
	alarm(ticks);
 a2b:	8b 45 f0             	mov    -0x10(%ebp),%eax
 a2e:	89 04 24             	mov    %eax,(%esp)
 a31:	e8 72 f9 ff ff       	call   3a8 <alarm>
	//failed - no free thread to use
	return -1;
 a36:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
 a3b:	c9                   	leave  
 a3c:	c3                   	ret    

00000a3d <safe_exit>:

// task 2.4


void safe_exit()
{
 a3d:	55                   	push   %ebp
 a3e:	89 e5                	mov    %esp,%ebp
 a40:	83 ec 28             	sub    $0x28,%esp
 a43:	eb 01                	jmp    a46 <safe_exit+0x9>
			}
		}
		if (tid == MAX_THREAD){
			exit();
		}
	}
 a45:	90                   	nop
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
 a46:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
 a4d:	eb 25                	jmp    a74 <safe_exit+0x37>
		{
			if (ttable[tid].state != T_FREE){
 a4f:	8b 45 f4             	mov    -0xc(%ebp),%eax
 a52:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 a58:	05 d0 13 00 00       	add    $0x13d0,%eax
 a5d:	8b 00                	mov    (%eax),%eax
 a5f:	85 c0                	test   %eax,%eax
 a61:	74 0d                	je     a70 <safe_exit+0x33>
				uthread_join(tid);
 a63:	8b 45 f4             	mov    -0xc(%ebp),%eax
 a66:	89 04 24             	mov    %eax,(%esp)
 a69:	e8 1d 02 00 00       	call   c8b <uthread_join>
				break;
 a6e:	eb 0a                	jmp    a7a <safe_exit+0x3d>
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
 a70:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 a74:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 a78:	7e d5                	jle    a4f <safe_exit+0x12>
			if (ttable[tid].state != T_FREE){
				uthread_join(tid);
				break;
			}
		}
		if (tid == MAX_THREAD){
 a7a:	83 7d f4 40          	cmpl   $0x40,-0xc(%ebp)
 a7e:	75 c5                	jne    a45 <safe_exit+0x8>
			exit();
 a80:	e8 73 f8 ff ff       	call   2f8 <exit>

00000a85 <uthread_switch>:
		}
	}
}

void uthread_switch()
{
 a85:	55                   	push   %ebp
 a86:	89 e5                	mov    %esp,%ebp
 a88:	83 ec 28             	sub    $0x28,%esp
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;
 a8b:	a1 ac 13 00 00       	mov    0x13ac,%eax
 a90:	8d 50 01             	lea    0x1(%eax),%edx
 a93:	89 d0                	mov    %edx,%eax
 a95:	c1 f8 1f             	sar    $0x1f,%eax
 a98:	c1 e8 1a             	shr    $0x1a,%eax
 a9b:	01 c2                	add    %eax,%edx
 a9d:	83 e2 3f             	and    $0x3f,%edx
 aa0:	89 d1                	mov    %edx,%ecx
 aa2:	29 c1                	sub    %eax,%ecx
 aa4:	89 c8                	mov    %ecx,%eax
 aa6:	89 45 f0             	mov    %eax,-0x10(%ebp)

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
 aa9:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 ab0:	eb 20                	jmp    ad2 <uthread_switch+0x4d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
 ab2:	8b 45 f0             	mov    -0x10(%ebp),%eax
 ab5:	8d 50 01             	lea    0x1(%eax),%edx
 ab8:	89 d0                	mov    %edx,%eax
 aba:	c1 f8 1f             	sar    $0x1f,%eax
 abd:	c1 e8 1a             	shr    $0x1a,%eax
 ac0:	01 c2                	add    %eax,%edx
 ac2:	83 e2 3f             	and    $0x3f,%edx
 ac5:	89 d1                	mov    %edx,%ecx
 ac7:	29 c1                	sub    %eax,%ecx
 ac9:	89 c8                	mov    %ecx,%eax
 acb:	89 45 f0             	mov    %eax,-0x10(%ebp)
{
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
 ace:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 ad2:	8b 45 f0             	mov    -0x10(%ebp),%eax
 ad5:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 adb:	05 d0 13 00 00       	add    $0x13d0,%eax
 ae0:	8b 00                	mov    (%eax),%eax
 ae2:	83 f8 02             	cmp    $0x2,%eax
 ae5:	74 06                	je     aed <uthread_switch+0x68>
 ae7:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 aeb:	7e c5                	jle    ab2 <uthread_switch+0x2d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
	}
	STORE_ESP(ttable[c_thread].esp);
 aed:	8b 15 ac 13 00 00    	mov    0x13ac,%edx
 af3:	89 e0                	mov    %esp,%eax
 af5:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 afb:	81 c2 c0 13 00 00    	add    $0x13c0,%edx
 b01:	89 42 04             	mov    %eax,0x4(%edx)
	STORE_EBP(ttable[c_thread].ebp);
 b04:	8b 15 ac 13 00 00    	mov    0x13ac,%edx
 b0a:	89 e8                	mov    %ebp,%eax
 b0c:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 b12:	81 c2 c0 13 00 00    	add    $0x13c0,%edx
 b18:	89 42 08             	mov    %eax,0x8(%edx)
	c_thread = n_thread;
 b1b:	8b 45 f0             	mov    -0x10(%ebp),%eax
 b1e:	a3 ac 13 00 00       	mov    %eax,0x13ac
	LOAD_EBP(ttable[c_thread].ebp);
 b23:	a1 ac 13 00 00       	mov    0x13ac,%eax
 b28:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b2e:	05 c0 13 00 00       	add    $0x13c0,%eax
 b33:	8b 40 08             	mov    0x8(%eax),%eax
 b36:	89 c5                	mov    %eax,%ebp
	LOAD_ESP(ttable[c_thread].esp);
 b38:	a1 ac 13 00 00       	mov    0x13ac,%eax
 b3d:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b43:	05 c0 13 00 00       	add    $0x13c0,%eax
 b48:	8b 40 04             	mov    0x4(%eax),%eax
 b4b:	89 c4                	mov    %eax,%esp
	alarm(THREAD_QUANTA);
 b4d:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
 b54:	e8 4f f8 ff ff       	call   3a8 <alarm>
}
 b59:	c9                   	leave  
 b5a:	c3                   	ret    

00000b5b <uthread_yield>:

void uthread_yield()
{
 b5b:	55                   	push   %ebp
 b5c:	89 e5                	mov    %esp,%ebp
 b5e:	83 ec 18             	sub    $0x18,%esp
	//store registers on stack
	asm("pusha");
 b61:	60                   	pusha  
	alarm(0);
 b62:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 b69:	e8 3a f8 ff ff       	call   3a8 <alarm>
	ttable[c_thread].state = T_RUNNABLE;
 b6e:	a1 ac 13 00 00       	mov    0x13ac,%eax
 b73:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b79:	05 d0 13 00 00       	add    $0x13d0,%eax
 b7e:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
	//change current thread
	uthread_switch();
 b84:	e8 fc fe ff ff       	call   a85 <uthread_switch>
	asm("popa");
 b89:	61                   	popa   
}
 b8a:	c9                   	leave  
 b8b:	c3                   	ret    

00000b8c <uthread_awake>:

// task 2.5

void uthread_awake()
{
 b8c:	55                   	push   %ebp
 b8d:	89 e5                	mov    %esp,%ebp
 b8f:	83 ec 10             	sub    $0x10,%esp
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
 b92:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
 b99:	eb 2c                	jmp    bc7 <uthread_awake+0x3b>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
 b9b:	a1 ac 13 00 00       	mov    0x13ac,%eax
 ba0:	6b d0 46             	imul   $0x46,%eax,%edx
 ba3:	8b 45 fc             	mov    -0x4(%ebp),%eax
 ba6:	01 d0                	add    %edx,%eax
 ba8:	83 c0 04             	add    $0x4,%eax
 bab:	8b 04 85 c4 13 00 00 	mov    0x13c4(,%eax,4),%eax
 bb2:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 bb8:	05 d0 13 00 00       	add    $0x13d0,%eax
 bbd:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
// task 2.5

void uthread_awake()
{
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
 bc3:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 bc7:	a1 ac 13 00 00       	mov    0x13ac,%eax
 bcc:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 bd2:	05 d0 14 00 00       	add    $0x14d0,%eax
 bd7:	8b 40 04             	mov    0x4(%eax),%eax
 bda:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 bdd:	7f bc                	jg     b9b <uthread_awake+0xf>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
}
 bdf:	c9                   	leave  
 be0:	c3                   	ret    

00000be1 <uthread_exit>:

void uthread_exit()
{
 be1:	55                   	push   %ebp
 be2:	89 e5                	mov    %esp,%ebp
 be4:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
 be7:	60                   	pusha  
	alarm(0);
 be8:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 bef:	e8 b4 f7 ff ff       	call   3a8 <alarm>
	asm("popa");
 bf4:	61                   	popa   
	ttable[c_thread].state = T_FREE;
 bf5:	a1 ac 13 00 00       	mov    0x13ac,%eax
 bfa:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c00:	05 d0 13 00 00       	add    $0x13d0,%eax
 c05:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	if (ttable[c_thread].tid != 0)
 c0b:	a1 ac 13 00 00       	mov    0x13ac,%eax
 c10:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c16:	05 c0 13 00 00       	add    $0x13c0,%eax
 c1b:	8b 00                	mov    (%eax),%eax
 c1d:	85 c0                	test   %eax,%eax
 c1f:	74 1d                	je     c3e <uthread_exit+0x5d>
		free(ttable[c_thread].stack);
 c21:	a1 ac 13 00 00       	mov    0x13ac,%eax
 c26:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c2c:	05 c0 13 00 00       	add    $0x13c0,%eax
 c31:	8b 40 0c             	mov    0xc(%eax),%eax
 c34:	89 04 24             	mov    %eax,(%esp)
 c37:	e8 10 fa ff ff       	call   64c <free>
 c3c:	eb 05                	jmp    c43 <uthread_exit+0x62>
	else
		safe_exit();
 c3e:	e8 fa fd ff ff       	call   a3d <safe_exit>
	uthread_awake();
 c43:	e8 44 ff ff ff       	call   b8c <uthread_awake>
	uthread_switch();
 c48:	e8 38 fe ff ff       	call   a85 <uthread_switch>
	asm("popa");
 c4d:	61                   	popa   
}
 c4e:	c9                   	leave  
 c4f:	c3                   	ret    

00000c50 <uthread_self>:

// task 2.6

int uthread_self()
{
 c50:	55                   	push   %ebp
 c51:	89 e5                	mov    %esp,%ebp
	return c_thread;
 c53:	a1 ac 13 00 00       	mov    0x13ac,%eax
}
 c58:	5d                   	pop    %ebp
 c59:	c3                   	ret    

00000c5a <uthread_sleep>:

// task 2.7

void uthread_sleep()
{
 c5a:	55                   	push   %ebp
 c5b:	89 e5                	mov    %esp,%ebp
 c5d:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
 c60:	60                   	pusha  
	alarm(0);
 c61:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 c68:	e8 3b f7 ff ff       	call   3a8 <alarm>
	ttable[c_thread].state = T_SLEEPING;
 c6d:	a1 ac 13 00 00       	mov    0x13ac,%eax
 c72:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c78:	05 d0 13 00 00       	add    $0x13d0,%eax
 c7d:	c7 00 03 00 00 00    	movl   $0x3,(%eax)
	uthread_switch();
 c83:	e8 fd fd ff ff       	call   a85 <uthread_switch>
	asm("popa");
 c88:	61                   	popa   
}
 c89:	c9                   	leave  
 c8a:	c3                   	ret    

00000c8b <uthread_join>:

int uthread_join(int tid)
{
 c8b:	55                   	push   %ebp
 c8c:	89 e5                	mov    %esp,%ebp
 c8e:	53                   	push   %ebx
 c8f:	83 ec 24             	sub    $0x24,%esp

	int ticks;
	asm("pusha");
 c92:	60                   	pusha  
	ticks = getTicks();
 c93:	e8 18 f7 ff ff       	call   3b0 <getTicks>
 c98:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 c9b:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 ca2:	e8 01 f7 ff ff       	call   3a8 <alarm>
	asm("popa");
 ca7:	61                   	popa   
	if (ttable[tid].state != T_FREE)
 ca8:	8b 45 08             	mov    0x8(%ebp),%eax
 cab:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 cb1:	05 d0 13 00 00       	add    $0x13d0,%eax
 cb6:	8b 00                	mov    (%eax),%eax
 cb8:	85 c0                	test   %eax,%eax
 cba:	74 5e                	je     d1a <uthread_join+0x8f>
	{
		//adding current thread to tid waiting list and going to sleep.
		ttable[tid].waiting[ttable[tid].wait_num++] = ttable[c_thread].tid;
 cbc:	8b 45 08             	mov    0x8(%ebp),%eax
 cbf:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 cc5:	05 10 01 00 00       	add    $0x110,%eax
 cca:	05 c0 13 00 00       	add    $0x13c0,%eax
 ccf:	8d 48 04             	lea    0x4(%eax),%ecx
 cd2:	8b 45 08             	mov    0x8(%ebp),%eax
 cd5:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 cdb:	05 d0 14 00 00       	add    $0x14d0,%eax
 ce0:	8b 40 04             	mov    0x4(%eax),%eax
 ce3:	8b 15 ac 13 00 00    	mov    0x13ac,%edx
 ce9:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 cef:	81 c2 c0 13 00 00    	add    $0x13c0,%edx
 cf5:	8b 12                	mov    (%edx),%edx
 cf7:	8b 5d 08             	mov    0x8(%ebp),%ebx
 cfa:	6b db 46             	imul   $0x46,%ebx,%ebx
 cfd:	01 c3                	add    %eax,%ebx
 cff:	83 c3 04             	add    $0x4,%ebx
 d02:	89 14 9d c4 13 00 00 	mov    %edx,0x13c4(,%ebx,4)
 d09:	83 c0 01             	add    $0x1,%eax
 d0c:	89 01                	mov    %eax,(%ecx)
		uthread_sleep();
 d0e:	e8 47 ff ff ff       	call   c5a <uthread_sleep>
		return 0;
 d13:	b8 00 00 00 00       	mov    $0x0,%eax
 d18:	eb 12                	jmp    d2c <uthread_join+0xa1>
	}
	asm("pusha");
 d1a:	60                   	pusha  
	alarm(ticks);
 d1b:	8b 45 f4             	mov    -0xc(%ebp),%eax
 d1e:	89 04 24             	mov    %eax,(%esp)
 d21:	e8 82 f6 ff ff       	call   3a8 <alarm>
	asm("popa");
 d26:	61                   	popa   
	return -1;
 d27:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
 d2c:	83 c4 24             	add    $0x24,%esp
 d2f:	5b                   	pop    %ebx
 d30:	5d                   	pop    %ebp
 d31:	c3                   	ret    

00000d32 <queue_init>:

void queue_init(struct tqueue *q)
{
 d32:	55                   	push   %ebp
 d33:	89 e5                	mov    %esp,%ebp
	q->head = 0;
 d35:	8b 45 08             	mov    0x8(%ebp),%eax
 d38:	c7 80 00 01 00 00 00 	movl   $0x0,0x100(%eax)
 d3f:	00 00 00 
	q->tail = 0;
 d42:	8b 45 08             	mov    0x8(%ebp),%eax
 d45:	c7 80 04 01 00 00 00 	movl   $0x0,0x104(%eax)
 d4c:	00 00 00 
}
 d4f:	5d                   	pop    %ebp
 d50:	c3                   	ret    

00000d51 <dequeue>:

struct uthread* dequeue(struct binary_semaphore* semaphore)
{
 d51:	55                   	push   %ebp
 d52:	89 e5                	mov    %esp,%ebp
 d54:	57                   	push   %edi
 d55:	56                   	push   %esi
 d56:	53                   	push   %ebx
	if (semaphore->queue->head == semaphore->queue->tail)
 d57:	8b 45 08             	mov    0x8(%ebp),%eax
 d5a:	8b 00                	mov    (%eax),%eax
 d5c:	8b 90 00 01 00 00    	mov    0x100(%eax),%edx
 d62:	8b 45 08             	mov    0x8(%ebp),%eax
 d65:	8b 00                	mov    (%eax),%eax
 d67:	8b 80 04 01 00 00    	mov    0x104(%eax),%eax
 d6d:	39 c2                	cmp    %eax,%edx
 d6f:	75 07                	jne    d78 <dequeue+0x27>
		return 0;
 d71:	b9 00 00 00 00       	mov    $0x0,%ecx
 d76:	eb 31                	jmp    da9 <dequeue+0x58>
	return semaphore->queue->uthreads[semaphore->queue->tail++ % MAX_THREAD];
 d78:	8b 45 08             	mov    0x8(%ebp),%eax
 d7b:	8b 18                	mov    (%eax),%ebx
 d7d:	8b 45 08             	mov    0x8(%ebp),%eax
 d80:	8b 10                	mov    (%eax),%edx
 d82:	8b 82 04 01 00 00    	mov    0x104(%edx),%eax
 d88:	89 c1                	mov    %eax,%ecx
 d8a:	c1 f9 1f             	sar    $0x1f,%ecx
 d8d:	c1 e9 1a             	shr    $0x1a,%ecx
 d90:	8d 34 08             	lea    (%eax,%ecx,1),%esi
 d93:	83 e6 3f             	and    $0x3f,%esi
 d96:	89 f7                	mov    %esi,%edi
 d98:	29 cf                	sub    %ecx,%edi
 d9a:	89 f9                	mov    %edi,%ecx
 d9c:	8b 0c 8b             	mov    (%ebx,%ecx,4),%ecx
 d9f:	83 c0 01             	add    $0x1,%eax
 da2:	89 82 04 01 00 00    	mov    %eax,0x104(%edx)
 da8:	90                   	nop
 da9:	89 c8                	mov    %ecx,%eax
}
 dab:	5b                   	pop    %ebx
 dac:	5e                   	pop    %esi
 dad:	5f                   	pop    %edi
 dae:	5d                   	pop    %ebp
 daf:	c3                   	ret    

00000db0 <enqueue>:

void enqueue(struct binary_semaphore* semaphore)
{
 db0:	55                   	push   %ebp
 db1:	89 e5                	mov    %esp,%ebp
 db3:	57                   	push   %edi
 db4:	56                   	push   %esi
 db5:	53                   	push   %ebx
	semaphore->queue->uthreads[semaphore->queue->head++ % MAX_THREAD] = &ttable[c_thread];
 db6:	8b 45 08             	mov    0x8(%ebp),%eax
 db9:	8b 18                	mov    (%eax),%ebx
 dbb:	8b 45 08             	mov    0x8(%ebp),%eax
 dbe:	8b 10                	mov    (%eax),%edx
 dc0:	8b 82 00 01 00 00    	mov    0x100(%edx),%eax
 dc6:	89 c1                	mov    %eax,%ecx
 dc8:	c1 f9 1f             	sar    $0x1f,%ecx
 dcb:	c1 e9 1a             	shr    $0x1a,%ecx
 dce:	8d 34 08             	lea    (%eax,%ecx,1),%esi
 dd1:	83 e6 3f             	and    $0x3f,%esi
 dd4:	89 f7                	mov    %esi,%edi
 dd6:	29 cf                	sub    %ecx,%edi
 dd8:	89 f9                	mov    %edi,%ecx
 dda:	8b 35 ac 13 00 00    	mov    0x13ac,%esi
 de0:	69 f6 18 01 00 00    	imul   $0x118,%esi,%esi
 de6:	81 c6 c0 13 00 00    	add    $0x13c0,%esi
 dec:	89 34 8b             	mov    %esi,(%ebx,%ecx,4)
 def:	83 c0 01             	add    $0x1,%eax
 df2:	89 82 00 01 00 00    	mov    %eax,0x100(%edx)
}
 df8:	5b                   	pop    %ebx
 df9:	5e                   	pop    %esi
 dfa:	5f                   	pop    %edi
 dfb:	5d                   	pop    %ebp
 dfc:	c3                   	ret    

00000dfd <binary_semaphore_init>:

void binary_semaphore_init(struct binary_semaphore* semaphore, int value)
{
 dfd:	55                   	push   %ebp
 dfe:	89 e5                	mov    %esp,%ebp
 e00:	83 ec 18             	sub    $0x18,%esp
	semaphore->queue = malloc(sizeof(struct tqueue));
 e03:	c7 04 24 08 01 00 00 	movl   $0x108,(%esp)
 e0a:	e8 76 f9 ff ff       	call   785 <malloc>
 e0f:	8b 55 08             	mov    0x8(%ebp),%edx
 e12:	89 02                	mov    %eax,(%edx)
	if (!value)
 e14:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
 e18:	75 0c                	jne    e26 <binary_semaphore_init+0x29>
		semaphore->state = S_LOCKED;
 e1a:	8b 45 08             	mov    0x8(%ebp),%eax
 e1d:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
 e24:	eb 0a                	jmp    e30 <binary_semaphore_init+0x33>
	else
		semaphore->state = S_FREE;
 e26:	8b 45 08             	mov    0x8(%ebp),%eax
 e29:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
}
 e30:	c9                   	leave  
 e31:	c3                   	ret    

00000e32 <binary_semaphore_down>:
void binary_semaphore_down(struct binary_semaphore* semaphore)
{
 e32:	55                   	push   %ebp
 e33:	89 e5                	mov    %esp,%ebp
 e35:	83 ec 28             	sub    $0x28,%esp
	//store amount of ticks left and prevent scheduler from switching
	int ticks;
	asm("pusha");
 e38:	60                   	pusha  
	ticks = getTicks();
 e39:	e8 72 f5 ff ff       	call   3b0 <getTicks>
 e3e:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 e41:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 e48:	e8 5b f5 ff ff       	call   3a8 <alarm>
	asm("popa");
 e4d:	61                   	popa   
	if (semaphore->state == S_LOCKED)
 e4e:	8b 45 08             	mov    0x8(%ebp),%eax
 e51:	8b 40 04             	mov    0x4(%eax),%eax
 e54:	83 f8 01             	cmp    $0x1,%eax
 e57:	75 1c                	jne    e75 <binary_semaphore_down+0x43>
	{
		enqueue(semaphore);
 e59:	8b 45 08             	mov    0x8(%ebp),%eax
 e5c:	89 04 24             	mov    %eax,(%esp)
 e5f:	e8 4c ff ff ff       	call   db0 <enqueue>
		uthread_sleep();
 e64:	e8 f1 fd ff ff       	call   c5a <uthread_sleep>
		alarm(0);
 e69:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 e70:	e8 33 f5 ff ff       	call   3a8 <alarm>
	}
	semaphore->state = S_LOCKED;
 e75:	8b 45 08             	mov    0x8(%ebp),%eax
 e78:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
	//allow the thread to run its remaining time
	alarm(ticks);
 e7f:	8b 45 f4             	mov    -0xc(%ebp),%eax
 e82:	89 04 24             	mov    %eax,(%esp)
 e85:	e8 1e f5 ff ff       	call   3a8 <alarm>

}
 e8a:	c9                   	leave  
 e8b:	c3                   	ret    

00000e8c <binary_semaphore_up>:
void binary_semaphore_up(struct binary_semaphore* semaphore)
{
 e8c:	55                   	push   %ebp
 e8d:	89 e5                	mov    %esp,%ebp
 e8f:	83 ec 28             	sub    $0x28,%esp
	int ticks;
	struct uthread *next;
	asm("pusha");
 e92:	60                   	pusha  
	ticks = getTicks();
 e93:	e8 18 f5 ff ff       	call   3b0 <getTicks>
 e98:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 e9b:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 ea2:	e8 01 f5 ff ff       	call   3a8 <alarm>
	asm("popa");
 ea7:	61                   	popa   


	if ((next = dequeue(semaphore)) == 0)
 ea8:	8b 45 08             	mov    0x8(%ebp),%eax
 eab:	89 04 24             	mov    %eax,(%esp)
 eae:	e8 9e fe ff ff       	call   d51 <dequeue>
 eb3:	89 45 f0             	mov    %eax,-0x10(%ebp)
 eb6:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 eba:	75 19                	jne    ed5 <binary_semaphore_up+0x49>
	{
		//no thread is waiting. release semaphore and restore alarm
		semaphore->state = S_FREE;
 ebc:	8b 45 08             	mov    0x8(%ebp),%eax
 ebf:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
		asm("pusha");
 ec6:	60                   	pusha  
		alarm(ticks);
 ec7:	8b 45 f4             	mov    -0xc(%ebp),%eax
 eca:	89 04 24             	mov    %eax,(%esp)
 ecd:	e8 d6 f4 ff ff       	call   3a8 <alarm>
		asm("popa");
 ed2:	61                   	popa   
 ed3:	eb 0f                	jmp    ee4 <binary_semaphore_up+0x58>
	}
	else
	{
		//threads are waiting. wake up the next thread and yield.
		next->state = T_RUNNABLE;
 ed5:	8b 45 f0             	mov    -0x10(%ebp),%eax
 ed8:	c7 40 10 02 00 00 00 	movl   $0x2,0x10(%eax)
		uthread_yield();
 edf:	e8 77 fc ff ff       	call   b5b <uthread_yield>
	}
}
 ee4:	c9                   	leave  
 ee5:	c3                   	ret    
